<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache"> 
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <link rel="stylesheet" href="../../../js/layui/css/layui.css" media="all">
    <script src="../../../js/layui/layui.js"></script>
    <script src="../../../js/myJQ.js"></script>

    <style type="text/css">
        .layui-input-block input{
            border: none
        }

        .layui-upload-list{
            vertical-align: middle;
        }

    </style>
</head>
<body>
<div>
    <button class="layui-btn layui-btn-sm layui-btn-normal" id="back" style="float: left">返回</button>
</div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
    <legend>商品详情</legend>
</fieldset>
    <div style="padding: 5px; background-color: #F2F2F2;">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md5">
                <div class="layui-card">
                    <div class="layui-card-header">商品信息</div>
                    <div class="layui-card-body">
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品名:</label>
                            <div class="layui-input-block" >
                                <input type="text" disabled id="productName" lay-verify="title" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品说明:</label>
                            <div class="layui-input-block" >
                                <input type="text" disabled id="description" lay-verify="title" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品价格:</label>
                            <div class="layui-input-block" >
                                <input type="text" disabled id="price" lay-verify="title" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">份数:</label>
                            <div class="layui-input-block" >
                                <input type="text" disabled id="num" lay-verify="title" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <div class="layui-col-md7">
                <div class="layui-card">
                    <div class="layui-card-header">商品图片</div>
                    <div class="layui-card-body">
                        <div class="layui-upload">
                            <div class="layui-upload-list" style="width: 50rem;height: 50rem;">
                                <img class="layui-upload-img" id="img" style="width: 35rem;height: auto;" onError="this.src='../../../images/defaulPic.png';">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(["jquery"],function () {
            var $ = layui.$;
            var basePath = "",param = "";

            $(function () {
                basePath = getRootPath();
                param = RequestParameter();
                getProductDetail(param);
            })
            //获取商品详情
            function getProductDetail(data) {
                debugger
                var params = {};
                params.productId = data.productId;
                $.ajax({
                    url:basePath+"/product/getProductList",
                    type:"get",
                    dataType:'json',
                    data:params,
                    cache:false,
                    beforeSend :function(xmlHttp){
                        xmlHttp.setRequestHeader("If-Modified-Since","0");  //添加
                        xmlHttp.setRequestHeader("Cache-Control","no-cache"); //添加
                    },
                    success:function (result) {
                        var obj = result.data[0];
                        console.log(JSON.stringify(result));
                        $("#productName").val(obj.productName);
                        $("#price").val(obj.price);
                        $("#num").val(obj.num);
                        $("#description").val(obj.description);
                        var img = obj.img;
                        if(typeof(img) !="undefined"){
                            $('#img').attr('src', "../"+obj.img)
                        }
                    }
                })
            }

            $("#back").click(function () {
                window.location.href = basePath+"/product/index";
            });

            /**
             * 如果是编辑，获取该数据的ID
             * @returns {Object}
             * @constructor
             */
            function RequestParameter(){
                var url = window.location.search; //获取url中"?"符后的字串
                var theRequest = new Object();
                if (url.indexOf("?") != -1) {
                    var str = url.substr(1);
                    var strs = str.split("&");
                    for(var i = 0; i < strs.length; i ++) {
                        theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
                    }
                }
                return theRequest;
            }
            
        });

    </script>

</body>
</html>